/*
 * @userName: 湫之恋
 * @Author: Seven
 * @Date: 2020-07-01 16:35:18
 * @LastEditors: Seven
 * @LastEditTime: 2020-07-01 22:57:33
 */
var axios = require("axios");

module.exports = {
    namespaced: true,
    state: {
        // 库存信息
        estimate: [],
        pageSize: 3,
        pageNumber: 1,
        maxNumbers: '',
        estimateNumber:"all",
        bool:true,
        itemNumber:[],
    },
    mutations: {
        // 修改estimateNumber的值
        updateEstimateNumber(state,data){
            state.estimateNumber=data.estimateNumber;
            state.pageNumber=1;
            state.maxNumbers="";
        },
        // 将返回的数据添加到数据仓库中
        getEstimateAll(state, data) {
            state.estimate = [...data.rows];
            state.maxNumbers=data.maxNumbers;
            state.itemNumber=[...data.itemNumber];
        },
        // 首页
        firstPage(state){
            if(state.pageNumber==1){
                state.bool=false;
            }else{
                state.pageNumber=1;
                state.bool=true;
            }
        },
        // 上一页
        previous(state){
            if(state.pageNumber==1){
                state.bool=false
            }else{
                state.pageNumber--;
                state.bool=true;
            }
            
        },
        // 下一页
        nextPage(state){
            if(state.pageNumber>=state.maxNumbers){
                state.bool=false
            }else{
                state.pageNumber++;
                state.bool=true;
            }
        },
        // 尾页
        maxPage(state){
            if(state.pageNumber>=state.maxNumbers){
                state.bool=false
            }else{
                state.pageNumber=state.maxNumbers;
                state.bool=true;
            }
            
        }
    },
    actions: {
        // 获取所有评价
        async getEstimateAllAsync(context,data) {
            // context.commit("updateEstimateNumber", data)
            console.log("执行")
            await axios.get("/estimate/getEstimateAll",{params:{pageSize:context.state.pageSize,pageNumber:context.state.pageNumber}}).then(({data}) => {
                console.log(data);
                context.commit("getEstimateAll", data);
            })
        },
        // 指定查询评价
        async getEstimateByEstimateNumberAsync(context, data) {
            // context.commit("updateEstimateNumber", data)
            await axios.get("/estimate/getEstimateByEstimateNumber", { params: { ...data,pageSize:context.state.pageSize,pageNumber:context.state.pageNumber } }).then(({ data }) => {
                context.commit("getEstimateAll", data)
            })
        }
    },
}